import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

import { main } from 'network/login'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    token: '',
    userInfo: {}
  },
  mutations: {
    updateToken (state, token) {
      state.token = token
    },
    updateUserInfo (state, data) {
      state.userInfo = data
    }
  },
  actions: {
    async getUserInfo ({ commit }) {
      const { data: res } = await main()
      commit('updateUserInfo', res.data)
    }
  },
  modules: {
  }
})
